/*
 * Copyright (C) 2020 Honeywell, Inc. All Rights Reserved.
 */
package org.thanos.iot.dao.graphic.dao;

import com.honeywell.tj.iot.entity.graphic.GraphicItemPoint;
import com.honeywell.tj.iot.vo.graphic.item.Item;
import org.apache.ibatis.jdbc.SQL;

/**
 * @ClassName PxViewInfoDao
 * @Author H241118
 * @Date 3/18/2020 9:00 AM
 **/
public class GraphicItemProvider {

    // 动态插入item
    public String dynamicAddItems(Item item) {
        return new SQL() {{
            INSERT_INTO("iot_graphic_item");
            if (item.getTop() != null) {
                VALUES("layout_top", "#{top}");
            }
            if (item.getLeft() != null) {
                VALUES("layout_left", "#{left}");
            }
            if (item.getWidth() != null) {
                VALUES("layout_width", "#{width}");
            }
            if (item.getHeight() != null) {
                VALUES("layout_height", "#{height}");
            }
            if (item.getComponentId() != null) {
                VALUES("component_id", "#{componentId}");
            }
            if (item.getViewId() != null) {
                VALUES("view_id", "#{viewId}");
            }
            if (item.getUuid() != null) {
                VALUES("uuid", "#{uuid}");
            }
            if (item.getEditable() != null) {
                VALUES("editable", "#{editable}");
            }
            if (item.getText() != null) {
                VALUES("text", "#{text}");
            }
        }}.toString();
    }

    // 动态插入point_item
    public String dynamicAddPointItems(GraphicItemPoint graphicItemPoint) {
        return new SQL() {{
            INSERT_INTO("iot_graphic_item_point");
            if (graphicItemPoint.getPointId() != null) {
                VALUES("point_id", "#{pointId}");
            }
            if (graphicItemPoint.getUuid() != null) {
                VALUES("uuid", "#{uuid}");
            }
        }}.toString();
    }
}
